<html>
<head>
    <meta charset="utf-8">
    <title>网站设置</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">

    <!-- <link rel="stylesheet" href="/css/theme5.css"> -->
    <script src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>
<body style="background-color: #fff">


<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                        <legend>网站设置</legend>
                    </fieldset>
                </div>

                <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                    <ul class="layui-tab-title">
                        <li class="layui-this">网站设置</li>
                        <li>开关设置</li>
                        <li>博主信息字段显示</li>
                        <li>微信设置</li>
                        <li>微博设置</li>
                        <li>腾讯设置</li>
                    </ul>
                    <div class="layui-tab-content" style="height: 100px;">


                        <div class="layui-tab-item layui-show">

                            <div class="layui-card-body ">
                                <form class="layui-form layui-form-pane" action="" id="siteForm">

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">网站名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="siteName" id="siteName" autocomplete="off"
                                                   value="${site.siteName}"
                                                   placeholder="请输入网站名称" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label for="regRoleId" class="layui-form-label"
                                               style="width:140px;">注册用户角色</label>
                                        <div class="layui-input-inline">


                                            <%if(isNotEmpty(roles)){%>
                                            <select name="regRoleId">
                                                <option value="">-请选择-</option>
                                                <% for(data in roles){ %>

                                                <%if(data.id==site.regRoleId){%>
                                                <option value="${data.id}" selected>${data.cname}</option>
                                                <%}else{%>
                                                <option value="${data.id}">${data.cname}</option>
                                                <%}%>

                                                <%} %>
                                            </select>
                                            <%}%>

                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <button type="button" class="layui-btn layui-btn-normal" lay-submit
                                                lay-filter="saveWebSet">保存
                                        </button>
                                    </div>

                                </form>
                            </div>


                        </div>

                        <div class="layui-tab-item">

                            <div class="layui-card-body ">
                                <form class="layui-form layui-form-pane" action="" id="switchForm">


                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">开启注册</label>
                                            <div class="layui-input-block">
                                                <input type="checkbox" name="open" lay-skin="switch"
                                                       lay-filter="openReg" lay-text="ON|OFF"
                                                <%if(site.openReg==true){%> checked <% }%> >
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">允许评论</label>
                                            <div class="layui-input-block">
                                                <input type="checkbox" name="open" lay-skin="switch"
                                                       lay-filter="openCmt" lay-text="ON|OFF"
                                                <%if(site.openCmt==true){%> checked <% }%> >
                                            </div>
                                        </div>
                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label" about="显示博主信息"
                                               style="width: 140px;">显示博主信息</label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" name="open" lay-skin="switch"
                                                   lay-filter="showAdminInfo" lay-text="ON|OFF"
                                            <%if(site.showAdminInfo==true){%> checked <%}%> }>
                                        </div>
                                    </div>


                                    <div class="layui-form-item">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">微信登录</label>
                                            <div class="layui-input-block">
                                                <input type="checkbox" disabled name="open" lay-skin="switch"
                                                       lay-filter="wechatLoginSwitch" lay-text="ON|OFF">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label">微博登录</label>
                                            <div class="layui-input-block">
                                                <input type="checkbox" disabled name="open" lay-skin="switch"
                                                       lay-filter="weboLoginSwitch" lay-text="ON|OFF">
                                            </div>
                                        </div>

                                        <div class="layui-inline">
                                            <label class="layui-form-label">QQ登录</label>
                                            <div class="layui-input-block">
                                                <input type="checkbox" disabled name="open" lay-skin="switch"
                                                       lay-filter="qqLoginSwitch" lay-text="ON|OFF">
                                            </div>
                                        </div>

                                    </div>

                                    <div class="layui-form-item">
                                        <label class="layui-form-label" style="width: 140px;">启用动态菜单</label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" name="open" lay-skin="switch"
                                                   lay-filter="dynamicMenu" lay-text="ON|OFF"
                                            <%if(site.dynamicMenu==true){%> checked <% }%> >
                                        </div>
                                    </div>

                                </form>
                            </div>


                        </div>


                        <div class="layui-tab-item">

                            <div class="layui-card-body ">
                                <form class="layui-form layui-form-pane" action="" id="websiteFieldForm">

                                    <div class="layui-form-item">
                                        <label class="layui-form-label">字段显示</label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" name="mobile" title="手机号" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"mobile")){%> checked<%}%> >
                                            <input type="checkbox" name="email" title="邮箱" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"email")){%> checked<%}%>>
                                            <input type="checkbox" name="school" title="毕业学校" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"school")){%> checked<%}%>>
                                            <input type="checkbox" name="profession" title="专业" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"profession")){%> checked<%}%>>
                                            <input type="checkbox" name="beginJobTime" title="开始工作时间" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"beginJobTime")){%> checked<%}%>>
                                            <input type="checkbox" name="endJobTime" title="结束工作时间" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"endJobTime")){%> checked<%}%>>
                                            <input type="checkbox" name="wechat" title="微信" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"wechat")){%> checked<%}%>>
                                            <input type="checkbox" name="weibo" title="微博" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"weibo")){%> checked<%}%>>
                                            <input type="checkbox" name="qq" title="QQ" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"qq")){%> checked<%}%>>
                                            <input type="checkbox" name="twitter" title="Twitter" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"twitter")){%> checked<%}%>>
                                            <input type="checkbox" name="facebook" title="Facebook" lay-filter="like"
                                            <%if(array.contain(site.showAdminFields,"facebook")){%> checked<%}%>>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>


                        <div class="layui-tab-item">
                            待开发
                        </div>

                        <div class="layui-tab-item">
                            待开发
                        </div>

                        <div class="layui-tab-item">
                            待开发
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;


        //注册监听
        form.on('switch(openReg)', function (data) {
            switchConfig("openReg");
            return false;
        });

        //评论监听
        form.on('switch(openCmt)', function (data) {
            switchConfig("openCmt");
            return false;
        });

        form.on('switch(dynamicMenu)', function (data) {
            layer.confirm('关闭后普通成员将具有管理员布局!', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                switchConfig("dynamicMenu");
            }, function () {

            });
            return false;
        });

        //显示博主信息监听
        form.on('switch(showAdminInfo)', function (data) {
            switchConfig("showAdminInfo");
            return false;
        });

        function switchConfig(key) {
            $.ajax({
                cache: false,
                type: "POST",
                contentType: 'application/json',
                url: "/site/switch/" + key,
                async: false,
                success: function (data) {
                    if (data.code === 0) {
                        layer.msg(data.message);
                    } else {
                        layer.msg(data.message, {
                            time: 2000
                        });
                    }
                },
                error: function (data) {
                    layer.msg(data.message);
                }
            });
        }


        //网站设置保存
        form.on('submit(saveWebSet)', function (data) {

            if (!data.field.siteName) {
                layer.msg("网站名称不能为空", {
                    time: 2000
                });
                return;
            }

            if (!data.field.regRoleId) {
                layer.msg("注册角色不能为空", {
                    time: 2000
                });
                return;
            }

            $.ajax({
                cache: false,
                type: "POST",
                contentType: 'application/json',
                url: "/site/website",
                data: JSON.stringify(data.field),
                async: false,
                success: function (data) {
                    if (data.code === 0) {
                        layer.msg(data.message);
                    } else {
                        layer.msg(data.message, {
                            time: 2000
                        });
                    }
                },
                error: function (data) {
                    layer.msg(data.message);
                }
            });
            return false;
        });

        // 显示字段监听
        form.on('checkbox(like)', function (data) {
            var key = data.elem.name
            $.ajax({
                cache: false,
                type: "POST",
                contentType: 'application/json',
                url: "/site/field/show/" + key,
                async: false,
                success: function (data) {
                    if (data.code === 0) {
                        layer.msg(data.message);
                    } else {
                        layer.msg(data.message, {
                            time: 2000
                        });
                    }
                },
                error: function (data) {
                    layer.msg(data.message);
                }
            });

            return false;
        });
    });
</script>


</body>
</html>